package com.pl.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pl.entity.DepartVO;
import com.pl.entity.Repairtable;
import com.pl.service.RepairtableService;
import com.pl.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * (Repairtable)表控制层
 *
 * @author makejava
 * @since 2024-04-29 20:16:08
 */
@RestController
@RequestMapping("/api/repair")
@CrossOrigin
public class RepairtableController {
    /**
     * 服务对象
     */
    @Autowired
    private RepairtableService repairtableService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping("/list/page")
    public R queryByPage(String pageNum) {
        return R.ok(this.repairtableService.queryByPage(pageNum));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public R queryById(@PathVariable("id") String id) {
        return R.ok(this.repairtableService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param repairtable 实体
     * @return 新增结果
     */
    @PostMapping("/save")
    public R add(Repairtable repairtable) {
        return R.ok(this.repairtableService.insert(repairtable));
    }

    /**
     * 编辑数据
     *
     * @param repairtable 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public R edit( Repairtable repairtable) {
        return R.ok(this.repairtableService.update(repairtable));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/del/{id}")
    public R deleteById(@PathVariable String id) {
        return R.ok(this.repairtableService.deleteById(id));
    }
    @PostMapping("/list/page")
    public R findByMap(int pageSize, int pageNum, @RequestParam HashMap<String,Object> map){
        PageHelper.startPage(pageNum,pageSize);
        List<DepartVO> byMap = repairtableService.findByMap(map);
        PageInfo<DepartVO> pageInfo = new PageInfo<>(byMap);
        return R.ok(pageInfo);
    }
    @PostMapping("/del/batch")
    public R deleteByList(@RequestParam List<String> list){
        int i = repairtableService.deleteList(list);
        if(i>0){
            return R.ok("success");
        }
        return R.fail("fail");
    }

}

